package com.goods.controller.business;


import com.goods.business.service.BizOutStockService;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.OutStockDetailVO;
import com.goods.common.vo.business.OutStockVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/business/outStock")
public class BizOutStockController {

    @Autowired
    private BizOutStockService bizOutStockService;

    @GetMapping("/findOutStockList")
    public ResponseBean findOutStockList(@RequestParam Map<String,Object> paramMap){
        //查询入库单
        PageVO<OutStockVO> outStockVOs = bizOutStockService.findOutStockList(paramMap);
        return ResponseBean.success(outStockVOs);
    }

    @PostMapping("/addOutStock")
    public ResponseBean addOutStock(@RequestBody OutStockVO outStockVO, HttpServletRequest request) {
        bizOutStockService.saveStock(outStockVO);
        return ResponseBean.success();
    }

    @GetMapping("/detail/{id}")
    public ResponseBean getDetails(@PathVariable Long id, @RequestParam Integer pageNum){
        OutStockDetailVO outStockDetailVO = bizOutStockService.findOutStockDetailById(id,pageNum);
        return ResponseBean.success(outStockDetailVO);
    }

    @PutMapping("/publish/{id}")
    public ResponseBean publishStock(@PathVariable Integer id){
        bizOutStockService.updateStatus(id,0);//通过
        return ResponseBean.success();
    }
    @PutMapping("/remove/{id}")
    public ResponseBean removeoutStock(@PathVariable Integer id){
        bizOutStockService.updateStatus(id,1);//移除
        return ResponseBean.success();
    }
    @PutMapping("/back/{id}")
    public ResponseBean rebackoutStock(@PathVariable Integer id){
        bizOutStockService.updateStatus(id,0);//移除
        return ResponseBean.success();
    }

    @GetMapping("/delete/{id}")
    public ResponseBean deleteOutStock(@PathVariable Integer id) {
        bizOutStockService.deleteById(id);
        return ResponseBean.success();
    }


}
